<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns information about available DSNs</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.odbc-cursor.html">« odbc_cursor</a></li>
      <li style="float: right;"><a href="function.odbc-do.html">odbc_do »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.uodbc.html">ODBC 函数</a></li>
    <li>Returns information about available DSNs</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.odbc-data-source" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">odbc_data_source</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">odbc_data_source</span> &mdash; <span class="dc-title">Returns information about available DSNs</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.odbc-data-source-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>odbc_data_source</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$odbc</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$fetch_type</code></span>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   This function will return the list of available DSN (after calling it
   several times).
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.odbc-data-source-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">odbc</code></dt>

     <dd>

      <p class="para">ODBC 连接标识符，详见
<span class="function"><a href="function.odbc-connect.html" class="function">odbc_connect()</a></span>。</p>
     </dd>

    
    
     <dt>
<code class="parameter">fetch_type</code></dt>

     <dd>

      <p class="para">
       The <code class="parameter">fetch_type</code> can be one of two constant types:
       <strong><code>SQL_FETCH_FIRST</code></strong>, <strong><code>SQL_FETCH_NEXT</code></strong>.
       Use <strong><code>SQL_FETCH_FIRST</code></strong> the first time this function is
       called, thereafter use the <strong><code>SQL_FETCH_NEXT</code></strong>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.odbc-data-source-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>false</code></strong> on error, an <span class="type">array</span> upon success, and <strong><code>null</code></strong> after fetching
   the last available DSN.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.odbc-data-source-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="odbc-data-source.example.basic">
   <p><strong>示例 #1 List available DSNs</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">odbc_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'dsn'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'user'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'pass'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dsn_info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">odbc_data_source</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQL_FETCH_FIRST</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">$dsn_info</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$dsn_info</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$dsn_info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">odbc_data_source</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQL_FETCH_NEXT</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [server] =&gt; dsn
    [description] =&gt; ODBC Driver 17 for SQL Server
)
Array
(
    [server] =&gt; other_dsn
    [description] =&gt; Microsoft Access Driver (*.mdb, *.accdb)
)</pre></div>
   </div>
  </div>
 </div>


</div></div></div></body></html>